#! /usr/bin/env perl
# author: maxiao
# date: 2023-03-09 11:52
# description: 测试哈希的相关方法

use v5.20;
use strict;
use utf8;
use warnings;

# 定义哈希
my %names = (
    'fred'    =>    'flintstone',
    'barney'  =>    'rubble',
    'wilma'   =>    'flintstone',
    # 确保每行一组的键-值后有逗号，方便后续的添加与维护（perl会忽略多余逗号）
);

# 获取用户输入
while ( 'hello' ) {
    print "please input your option; pressing Ctrl-C to exit script: ";
    my $input = <STDIN>;
    chomp $input;
    my $result = $names{$input};
    if ( defined($result) ) {
        print "result -----> $result\n";
    } else {
        print "您输入的数据不在哈希中，请重新输入!\n";
    }
}
